import Vue from 'vue'
import App from './App.vue'  

// import store from './store'
// import router from './router'
import rs from './utils/routerState.js'
let { router, store } = rs;

Vue.config.productionTip = false

// 导入api 文件并添加到 vue 原型中
import api from "@/utils/api.js";
Vue.prototype.api = api;

// 导入数据请求的方法并添加到 vue 原型中
import req from "@/utils/req.js";
let getSource = req.getSource;
Vue.prototype.getsource = getSource;

//mint-ui 
// 导入 图片懒加载组件
import { Lazyload } from 'mint-ui';
Vue.use(Lazyload);
import { Spinner } from 'mint-ui';
Vue.component(Spinner.name, Spinner);


// 导入自定义的audio对象
import audio from '@/utils/audio.js';
Vue.prototype.audio = audio;

//导入 fastclick 解决pc与移动的300ms问题
import FastClick from 'fastclick'
FastClick.attach(document.body);

import { Swipe, SwipeItem } from 'mint-ui';

Vue.component(Swipe.name, Swipe);
Vue.component(SwipeItem.name, SwipeItem);

// 自定义的全局组件
import globalComponents from '@/components/globalComponents'

Vue.use(globalComponents);

Vue.directive('touch', {
  bind: function (el, binding) {
    let startX, moveX;
    el.addEventListener('touchstart', function (e) {
      //开始坐标
      startX = e.changedTouches[0].clientX;
    })
    el.addEventListener('touchmove', function (e) {
      //移动坐标
      moveX = e.changedTouches[0].clientX;
     
      
    })
    el.addEventListener('touchend', function (e) {
    
      if (moveX - startX > 200 && binding.modifiers.right) {
        console.log('向右', binding);
        //传入的函数,可以执行
        let dir = "right";
        binding.value({e,dir});
      } else if (moveX - startX < -200 && binding.modifiers.left) {
        console.log('向左', binding);
        let dir = "left";
        binding.value({ e, dir });
      }
    })
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    this.audio.vm = this;
  }
}).$mount('#app')
